// ControlEnemy.js

cc.Class({
    extends: cc.Component,

    properties: {
        mSpeed: 300
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {
        this.minX = -this.node.parent.width / 2 + this.node.width / 2;
        this.maxX = Math.abs(this.minX);
    },

    update(dt) {
        let currentPos = this.node.getPosition();

        if (currentPos.x < this.minX) {
            this.mSpeed = Math.abs(this.mSpeed);
        } else if (currentPos.x > this.maxX) {
            this.mSpeed = -Math.abs(this.mSpeed);
        }

        this.node.x += this.mSpeed * dt;
    }
});
